package com.geovis.emergency.spd.entity.pc.pojo.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.geovis.emergency.spd.entity.system.pojo.node.INode;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 通用树形VO
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/6/28
 */
@Data
@ApiModel(value = "TreeVO", description = "通用树形VO")
public class TreeVO  implements INode<TreeVO> {
    /**
     * 主键ID
     */
    private String id;

    /**
     * 父节点ID
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private String parentId;

    /**
     * 父节点名称
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private String parentName;

    /**
     * 节点名称
     */
    private String name;
    /**
     * 是否有子孙节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Boolean hasChildren;

    /**
     * 子孙节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeVO> children;


    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object extra;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object extra1;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object extra2;

    @Override
    public Boolean getHasChildren() {
        return getChildren().size() > 0 ? true:null;
    }
    @Override
    public List<TreeVO> getChildren() {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        return this.children;
    }
}
